package com.woniuxy.receivables.controller;

import com.woniuxy.commons.entity.Receivables;
import com.woniuxy.commons.request.ResPage;
import com.woniuxy.commons.request.ResponseResult;
import com.woniuxy.commons.vo.AddAddTimeToReceivablesVo;
import com.woniuxy.commons.vo.SearchProjectVo;
import com.woniuxy.receivables.service.ReceivablesService;
import com.woniuxy.receivables.vo.InvestsVo;
import com.woniuxy.receivables.vo.ReceivablesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/receivables")
public class ReceivablesController {

    @Resource
    private ReceivablesService receivablesService;

    @GetMapping("/refund/{pno}")
    public ResponseResult<Boolean> refund(@PathVariable("pno") String pno){
        return new ResponseResult<>(ResponseResult.OK, receivablesService.refund(pno));
    }

    @PutMapping("/setAddTime")
    public ResponseResult<Boolean> setAddTime(@RequestBody AddAddTimeToReceivablesVo addAddTimeToReceivablesVo){
        return new ResponseResult<>(ResponseResult.OK, receivablesService.setAddTime(addAddTimeToReceivablesVo));
    }

    @GetMapping("/findAllReceivablesByPno/{pno}")
    public ResponseResult<List<Receivables>> findAllReceivablesByPno(@PathVariable("pno") String pno){
        return new ResponseResult<>(ResponseResult.OK, receivablesService.findAllReceivablesByPno(pno));
    }

    @PostMapping("/searchInvests")
    public ResponseResult<ResPage<List<InvestsVo>>> searchInvests(@RequestBody SearchProjectVo searchProjectVo){
        System.out.println("多条件查询");
        ResPage<List<InvestsVo>> resPage = receivablesService.searchInvests(searchProjectVo);
        return new ResponseResult<>(ResponseResult.OK, resPage);
    }

    @PostMapping("/searchReceivables")
    public ResponseResult<ResPage<List<ReceivablesVo>>> searchReceivables(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<ReceivablesVo>> resPage = receivablesService.searchReceivables(searchProjectVo);
        return new ResponseResult<>(ResponseResult.OK, resPage);
    }


}
